import { handleSearchLoading } from "@userList/search";
import { WindowResizeChange } from "@/utils/tools";
import {
  columns,
  defaultColumns,
  defaultSearchList,
  drawerFormState,
  resetFormState,
  searchList,
  tableActiveKey,
  tabsOptions,
  winRef,
} from "./store";
import { calcWrapHeight } from "./utils";
import { refreshTable } from ".";
const searchLoading = ref(false);
const resetLoading = ref(false);
export const searchConfig = () => {
  const defineSearch = {
    okText: getProxyT("base.query"),
    cancelText: getProxyT("base.reset"),
    searchLoading,
    resetLoading,
    refreshTableData: async (searchParams: any, type: any) => {
      searchParams.status =
        searchParams.status === "" ? undefined : searchParams.status;
      handleSearchLoading(true, type, defineSearch);
      await refreshTable(searchParams);
      handleSearchLoading(false, type, defineSearch);
    },
    tabsSlot: {
      activeKey: tableActiveKey,
      on: {
        change(tableActiveKey: any) {
          initObjAttr(columns, defaultColumns[tableActiveKey]);
          searchList.value = defaultSearchList[tableActiveKey];
          resetFormState(drawerFormState);
          if (tableActiveKey === 0)
            removeEvent(
              window,
              "resize",
              winRef.value?.callback ?? (() => {}),
              false
            );
          if (tableActiveKey === 1) {
            calcWrapHeight();
            winRef.value = new WindowResizeChange(calcWrapHeight, 300);
          }
          refreshTable();
        },
      },
      options: tabsOptions,
    },
    searchList,
  };
  return defineSearch;
};
